package yja.gzw.app.activity

import android.content.Intent
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import yja.gzw.app.R
import yja.gzw.app.adapter.ChengjieAdapter

import yja.gzw.app.base.BaseActivity
import yja.gzw.app.databinding.ActivityChengjieBinding

import yja.gzw.app.model.UserData
import yja.gzw.app.viewmodel.Mainviewmodel
import com.google.android.material.tabs.TabLayout
import yja.gzw.app.fragmentview.ChengjieerFragment
import yja.gzw.app.fragmentview.ChengjieliuFragment
import yja.gzw.app.fragmentview.ChengjiesanFragment
import yja.gzw.app.fragmentview.ChengjiesiFragment
import yja.gzw.app.fragmentview.ChengjiewuFragment
import yja.gzw.app.fragmentview.ChengjieyiFragment

class ChengjieActivity :BaseActivity<Mainviewmodel, ActivityChengjieBinding>(R.layout.activity_chengjie){
    private lateinit var fabiada: ChengjieAdapter

    val list_title= mutableListOf<String>("全部","待确认","待发货","待收货","待评价","撤销订单")
    val listfragment= mutableListOf<Fragment>(
        ChengjieyiFragment(),  ChengjieerFragment(),
        ChengjiesanFragment(),  ChengjiesiFragment(),
        ChengjiewuFragment(),  ChengjieliuFragment()

    )
    override fun initView() {
        binding.fanhui.setOnClickListener {
            finish()
        }
        binding.sousuo.setOnClickListener {
            val inten=Intent(this,SousouChengjieActivity::class.java)
            startActivity(inten)
        }



        binding.viewpager.adapter=object : FragmentPagerAdapter(supportFragmentManager){
            override fun getCount(): Int {

                return listfragment.size

            }

            override fun getItem(position: Int): Fragment {

                return listfragment[position]

            }

            override fun getPageTitle(position: Int): CharSequence {
                return list_title[position]
            }

        }

        binding.tabss.setupWithViewPager(binding.viewpager)




        //viewmodel.onchengjiewang(UserData.token, mapOf("keyword" to "","status" to "all","page" to "1","pagesize" to "10"))


//        binding.tabss.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
//            override fun onTabSelected(tab: TabLayout.Tab) {
//                if(tab.position==0){
//                    viewmodel.onchengjiewang(UserData.token, mapOf("keyword" to "","status" to "all","page" to "1","pagesize" to "10"))
//
//                }else if(tab.position==1){
//                    viewmodel.onchengjiewang(UserData.token, mapOf("keyword" to "","status" to "2","page" to "1","pagesize" to "10"))
//
//
//                }else if(tab.position==2){
//                    viewmodel.onchengjiewang(UserData.token, mapOf("keyword" to "","status" to "3","page" to "1","pagesize" to "10"))
//
//
//                }else if(tab.position==3){
//                    viewmodel.onchengjiewang(UserData.token, mapOf("keyword" to "","status" to "4","page" to "1","pagesize" to "10"))
//
//
//                }else if(tab.position==4){
//                    viewmodel.onchengjiewang(UserData.token, mapOf("keyword" to "","status" to "5","page" to "1","pagesize" to "10"))
//
//
//                }else if(tab.position==5){
//                    viewmodel.onchengjiewang(UserData.token, mapOf("keyword" to "","status" to "-1","page" to "1","pagesize" to "10"))
//
//                }
//
//
//            }
//
//            override fun onTabUnselected(tab: TabLayout.Tab?) {
//
//            }
//
//            override fun onTabReselected(tab: TabLayout.Tab?) {
//
//            }
//        })


//        for (i in 0  until list_title.size ){
//            val tab = binding.tabss.newTab()
//            binding.tabss.addTab(tab.setText(list_title[i]))
//        }


    }



    override fun dataObservese() {

//        viewmodel.onchengjie.observe(this, Observer {
//            if(it.code==1){
//
//                binding.recview.layoutManager=
//                    LinearLayoutManager(this)
//                fabiada= ChengjieAdapter(this,it.data.data)
//                binding.recview.adapter= fabiada
//
//
//
//
//            }else{
//
//                Toast.makeText(this,it.msg, Toast.LENGTH_SHORT).show()
//            }
//
//
//        })


    }
}